/**   
 * @Title: CheDanCommunicater.java 
 * @Package: com.esun.rabbit2.communicaters 
 * @Description: (撤单接口) 
 * @Author: Billy qigs@500wan.com   
 * @Date: 2011-6-30 下午02:19:14  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: CheDanCommunicater
 * @Description: (跟单投注撤单接口)
 * @Author: Billy qigs@500wan.com
 * @Date: 2011-6-30 下午02:19:14
 */
public class CheDanCommunicater extends ServerCommunicater {
	private String msgServer;
	private String money;
	private String USERSESSION = UserInfo.getUserInfo().getUserSession();

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String str) {
		this.msgServer = str;
	}

	public String getMoney() {
		return money;
	}

	public void setMoney(String str) {
		this.money = str;
	}

	public boolean isCheDan(String lotid, String buyid, String playid) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		boolean isSucceed = false;
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_HEMAI_CHEDAN));
		list.add(mapItem(BussinessCode.PASER_CK, USERSESSION));
		list.add(mapItem(Key.KEY_LOTID, lotid));
		list.add(mapItem(Key.KEY_BUYID, buyid));
		list.add(mapItem(Key.KEY_PLAYID, playid));

		super.getServerResponse(list, true);
		setMsgServer(super.getServerMsg());
		if (super.getState() == 100) {
			setMoney(super.getResult().get(Key.KEY_MONEY));
			isSucceed = true;
		}

		return isSucceed;
	}

	public boolean userOrderCheDan(String lotid, String pid, String playid) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		boolean isSucceed = false;

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_HEMAI_FAQIREN_CHEDAN));
		list.add(mapItem(BussinessCode.PASER_CK, USERSESSION));
		list.add(mapItem(Key.KEY_LOTID, lotid));
		list.add(mapItem(Key.KEY_PID, pid));
		list.add(mapItem(Key.KEY_PLAYID, playid));

		super.getServerResponse(list, true);
		setMsgServer(super.getServerMsg());
		if (super.getState() == 100) {
			setMoney(super.getResult().get(Key.KEY_MONEY));
			isSucceed = true;
		}

		return isSucceed;
	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
